package cn.edu.xmu.datamining.tangzk.mralgos.secondarysort;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

public class SecondarySortMapper extends
		Mapper<LongWritable, Text, KeyPair, Text> {

	protected void map(
			LongWritable key,
			Text value,
			org.apache.hadoop.mapreduce.Mapper<LongWritable, Text, KeyPair, Text>.Context context)
			throws java.io.IOException, InterruptedException {
		// format: id1[int], id2[String], value
		String val = value.toString();
		String[] flds = val.split(",");
		if (flds.length < 3) {
			return;
		}
		int id1 = Integer.valueOf(flds[0]);
		String id2 = flds[1].trim();
		KeyPair pair = new KeyPair(id1, id2);
		context.write(pair, new Text(flds[2].trim()));
	};

}
